﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DxMvcApplication.Areas.Administrator.Models;
using DxMvcApplication.Repositories.Core.Security;
using DxMvcApplication.Repositories.Implementations.Security;

namespace DxMvcApplication.Areas.Administrator.Controllers
{
    public class SharedController : AdminController
    {
        private readonly ISiteRepository _siteRepository;
        private readonly IPermissionRepository _permissionRepository;
        
        public SharedController()
        {
            _siteRepository = new SiteRepository();
            _permissionRepository = new PermissionRepository();
        }

        public ActionResult Navigation()
        {
            return View();
        }

        /// <summary>
        /// Navigations the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public PartialViewResult Navigation(int id)
        {
            var result = _siteRepository.GetList(UserId, id);
            return PartialView(result.ToModel());
        }

        /// <summary>
        /// Subs the navigation.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public PartialViewResult SubNavigation(int id)
        {
            var result = _siteRepository.GetList(UserId, id);
            return result.Count > 0 ? PartialView(result.ToModel()) : null;
        }
    }
}
